import { createSSRApp } from "vue";
// import "./style.css";
import App from "./App.vue";
import { createSSRouter } from "./router";
import ElementPlus, { ElMessage } from 'element-plus'
import 'element-plus/dist/index.css'
// 引入全局语言国际化
import { createSSI18n } from './Language/i18n'
// TODO: vuex
import { createSSRStore, key } from './store'
import { sync } from 'vuex-router-sync'


export function createApp() {
    const app = createSSRApp(App)
    const store = createSSRStore()
    const router = createSSRouter()
    const i18n = createSSI18n()
    sync(store, router)
    // 挂载全局消息弹窗
    app.config.globalProperties.$message = ElMessage
    app.use(store, key)
    app.use(router)
    app.use(ElementPlus)
    app.use(i18n)
    return { app, router, store }
}

export function asyncDataFilter(actived: any, store: any, route: any) {
    return Promise.all(actived.map((Component: any) => {
        if (Component.asyncData) {
            return Component.asyncData({
                store,
                route
            })
        }
    }))
}